﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace DreametryMIS
{
    public static class CommentPrompt
    {
        public static string x;
        public static ContextMenuStrip contxtmenu;
        public static string ShowDialog(string text, string caption)
        {
            TextBox textBox;

            Form prompt = new Form()
            {
                Width = 500,
                Height = 150,
                FormBorderStyle = FormBorderStyle.FixedDialog,
                Text = caption,
                StartPosition = FormStartPosition.CenterScreen
            };
            Label textLabel = new Label() { Left = 50, Top = 20, Text = text };
            textBox = new TextBox() { Left = 50, Top = 50, Width = 400 };
            Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK };
            FileSystemWatcher systemwatch = new FileSystemWatcher() { Path = @"C:\Users\Client\Documents", EnableRaisingEvents = true };
            NotifyIcon notify = new NotifyIcon() { ContextMenuStrip = contxtmenu, Icon = DreametryMIS.Properties.Resources.comments, Visible = true };
            contxtmenu = new ContextMenuStrip();
            contxtmenu.Opening += cms_Opening;
            // ToolStrip ts = new ToolStrip();
            // ToolStripDropDownButton contxtToolStripDropDownButton = new ToolStripDropDownButton("Fruit", null, null, "Fruit");
            // ts.Items.Add(contxtToolStripDropDownButton);
            //ts.Dock = DockStyle.Top;
            // contxtToolStripDropDownButton.DropDown = contxtmenu;
            // MenuStrip ms = new MenuStrip();
            // ToolStripMenuItem contxtToolStripMenuItem = new ToolStripMenuItem("Fruit", null, null, "Fruit");
            // ms.Items.Add(contxtToolStripMenuItem);
            // ms.Dock = DockStyle.Top;
            // contxtToolStripMenuItem.DropDown = contxtmenu;
            prompt.ContextMenuStrip = contxtmenu;
            // prompt.Controls.Add(ts);
            Button b = new Button();
            b.Location = new System.Drawing.Point(60, 60);
            prompt.Controls.Add(b);
            b.ContextMenuStrip = contxtmenu;


            systemwatch.Created += (sender, e) =>
            {

                String path, result;
                path = e.FullPath;

                result = System.IO.Path.GetFileName(path);
                //y = Path.GetDirectoryName(result.TrimEnd(Path.DirectorySeparatorChar));
                x = Path.GetFileName(result);

                notify.ShowBalloonTip(5000, "asgasas", " New Comment " + textBox.Text +
                     "                                  " +
                                "                               ", ToolTipIcon.Info);

            };




            confirmation.Click += (sender, e) =>
            {
                notify.ShowBalloonTip(5000, "asgasas", " New Comment " + textBox.Text +
                   "                                  " +
                              "                               ", ToolTipIcon.Info);
                create(textBox.Text.ToString());
                prompt.Hide();
            };

            prompt.Controls.Add(textBox);


            prompt.Controls.Add(confirmation);
            prompt.Controls.Add(textLabel);




            prompt.AcceptButton = confirmation;

            return prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "";


        }

        public static void create(String text)
        {
            String asd = "C:\\Users\\Client\\Documents\\" + text + "";
            if (!File.Exists(asd))
            {
                // Create a file to write to.
                using (StreamWriter sw = File.CreateText(asd))
                {
                    sw.WriteLine("Hello");
                    sw.WriteLine("And");
                    sw.WriteLine("Welcome");
                }
            }

            // Open the file to read from.
            using (StreamReader sr = File.OpenText(asd))
            {
                string s = "";
                while ((s = sr.ReadLine()) != null)
                {
                    Console.WriteLine(s);
                }
            }

        }

        public static void cms_Opening(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Control c = contxtmenu.SourceControl as Control;
            ToolStripDropDownItem tsi = contxtmenu.OwnerItem as ToolStripDropDownItem;
            contxtmenu.Items.Clear();
            if (c != null)
            {
                // Add custom item (Form)
                contxtmenu.Items.Add("Source: " + c.GetType().ToString());
            }
            else if (tsi != null)
            {
                // Add custom item (ToolStripDropDownButton or ToolStripMenuItem)
                contxtmenu.Items.Add("Source: " + tsi.GetType().ToString());
            }

            // Populate the ContextMenuStrip control with its default items.
            contxtmenu.Items.Add("-");
            contxtmenu.Items.Add("Show");
            contxtmenu.Items.Add("Exit");
            contxtmenu.Items.Add("wew");

            // Set Cancel to false. 
            // It is optimized to true based on empty entry.
            e.Cancel = false;


        }
    }
}
